#include <iostream>
using namespace std;
int n;
int v[10];
int main()
{
	cin >> n;
	for (int i = 1; i <= 6; i++) cin >> v[i];
	int sum = 0, d = 0;
	for (int i = 1; i <= n; i++)
	{
		int x; cin >> x;
		if (x) d++;
		else d = 0;
		int y = 0;
		if (d == 0) y = 0;
		else if (d < 3) y = v[1];
		else if (d < 7) y = v[2];
		else if (d < 30) y = v[3];
		else if (d < 120) y = v[4];
		else if (d < 365) y = v[5];
		else y = v[6];
		sum += y;
	}
	cout << sum << endl;
	return 0;
}